home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
print
/
890ps.arc
/
PSERVER.C
< prev
next >
Wrap
Text File
|
1989-12-18
|
5KB
|
187 lines
/* Program to service print jobs. */
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <netware.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#define MODECOUNT 4
typedef enum {PostScript,PostScriptInteractive,Diablo630,LaserJet} Modes;
int stop()
{
static int abort_flag = 0;
return(abort_flag=(abort_flag || (kbhit() && (getch()==0x1B))));
}
void die(const char *msg1, const char *msg2, byte code)
{
cprintf("Failed during %s%s (%0#2x).\n",msg1,msg2,code);
Logout();
exit(1);
}
void out(const char *data, unsigned len)
{
union REGS i_regs,o_regs;
i_regs.h.ah = 0x00;
i_regs.x.dx = 0x00;
while (len!=0) {
if (*data!=0) {
i_regs.h.al = *data;
do {
int86(0x17,&i_regs,&o_regs);
} while (((o_regs.h.ah&0x01)==1) && !(stop()));
}
data++;
len--;
}
}
void SetMode(Modes NewMode)
{
static Modes CurrMode = PostScript;
const struct {
char PreMode[50];
unsigned PreWait;
unsigned MidWait;
char PostMode[50];
unsigned PostWait;
char Desc[25];
} ModeInfo[MODECOUNT] = {{"",0,0,"",0,"PostScript"},
{"statusdict begin 1 setsoftwareiomode end\x04",4000,10000,"statusdict begin 1 setsoftwareiomode end\x04",4000,"PostScript Interactive"},
{"statusdict begin 2 setsoftwareiomode end\x04",4000,10000,"\x1B\x7F\x30\x04",10000,"Diablo 630"},
{"statusdict begin 5 setsoftwareiomode end\x04",4000,10000,"\x1B\x7F\x30\x04",10000,"LaserJet"}};
if (NewMode!=CurrMode) {
if (ModeInfo[CurrMode].MidWait!=0) {
delay(ModeInfo[CurrMode].MidWait);
}
cprintf(" Ending %s...\n",ModeInfo[CurrMode].Desc);
out(ModeInfo[CurrMode].PostMode,strlen(ModeInfo[CurrMode].PostMode));
if (ModeInfo[CurrMode].PostWait!=0) {
delay(ModeInfo[CurrMode].PostWait);
}
cprintf(" Switching to %s...\n",ModeInfo[NewMode].Desc);
out(ModeInfo[NewMode].PreMode,strlen(ModeInfo[NewMode].PreMode));
if (ModeInfo[NewMode].PreWait!=0) {
delay(ModeInfo[NewMode].PreWait);
}
CurrMode = NewMode;
}
}
void Process(Modes mode, dword id)
{
int file;
char buf[1024];
int len;
QueueJobInfoStruct info;
PrintJobClientStruct client;
while ((ServiceQueueJobAndOpenFile(id,0xFFFF,&info)==0) && !(stop())) {
SetMode(mode);
if((file=_open("NETQ",O_RDONLY|SH_NOINHERIT|SH_DENYRW))!=-1) {
while ((len=_read(file,buf,sizeof(buf)))>0) {
if (stop()) {
break;
}
out(buf,len);
}
_close(file);
}
if (stop()) {
AbortServicingQueueJobAndFile(id,info._JobNumber);
cputs(" Aborting...\n");
} else {
if ((ReadPrintJobInfo(id,info._JobNumber,&client)==0) && ((client._Flags&0x8)==0)) {
out("\x0C",1);
}
FinishServicingQueueJobAndFile(id,info._JobNumber,0);
cprintf(" Finished printing (%s->%s)...\n",client._BannerName,client._BannerFile);
}
}
}
byte AttachQueueServerToPrintQueue(const char *name, dword *id)
{
byte res;
if ((res=GetBinderyObjectID(name,0x0003,id))==0) {
res=AttachQueueServerToQueue(*id);
}
return(res);
}
main()
{
byte res;
struct{
char Name[25];
dword ID;
} queue[MODECOUNT] = {{"POSTSCRIPT",0},
{"POSTSCRIPTINTERACTIVE",0},
{"DIABLO630",0},
{"LASERJET",0}};
unsigned i,j;
if ((res=LoginToFileServer("LC890",0x0007,"LC890"))!=0) {
die("login","",res);
}
cputs("LC890 printer server is logged on...\n");
i = PostScript;
while (i<MODECOUNT) {
if ((res=AttachQueueServerToPrintQueue(queue[i].Name,&queue[i].ID))!=0) {
j = PostScript;
while (j<i) {
DetachQueueServerFromQueue(queue[j].ID);
j++;
}
die("attach to ",queue[i].Name,res);
} else {
cprintf("Attached to %s\n",queue[i].Name);
}
i++;
}
while (!stop()) {
cputs(" Looping...\n");
for(i=PostScript;i<MODECOUNT;i++) {
Process(i,queue[i].ID);
if (stop()) {
break;
}
}
cputs(" Pausing...\n");
delay(10000);
}
cputs("Detaching...\n");
for (i=PostScript;i<MODECOUNT;i++) {
DetachQueueServerFromQueue(queue[i].ID);
}
cputs("Logging out...\n");
Logout();
cputs("Done.\n");
return(0);
}